package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.AttendAuditBtyArea;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPaymentOrderConfigMugua;
import cn.stylefeng.guns.sys.modular.system.entity.BtyPaymentOrderDetails;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPaymentOrderAndYybbParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPaymentOrderDetailsParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyPaymentOrderParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyPaymentOrderAndYybbResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyPaymentOrderDetailsService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 店名日营业现金支付订单表控制器
 *
 * @author wjk
 * @Date 2021-12-07 17:32:34
 */
@Controller
@RequestMapping("/btyPaymentOrderDetails")
public class BtyPaymentOrderDetailsController extends BaseController {

    private String PREFIX = "/modular/system/btyPaymentOrderDetails";

    @Autowired
    private BtyPaymentOrderDetailsService btyPaymentOrderDetailsService;



    /**
     * 跳转到日帐现金收款查询
     *
     * @author wjk
     * @Date 2021-12-08
     */
    @RequestMapping("/btyPaymentOrderYybb")
    public String btyPaymentOrderYybb() {
        return PREFIX + "/btyPaymentOrderYybb.html";
    }

    /**
     * 跳转到手动支付现金
     *
     * @author wjk
     * @Date 2021-12-09
     */
    @RequestMapping("/btyPaymentOrderDetailsManualOperation")
    public String btyPaymentOrderDetailsManualOperation(@RequestParam("id") String id,
                                                        @RequestParam("xj") String xj,
                                                        @RequestParam("xjbz") String xjbz,
                                                        @RequestParam("sumTodayCash") String sumTodayCash,
                                                        @RequestParam("dianming") String dianming,
                                                        @RequestParam("yaoma") String yaoma,
                                                        @RequestParam("yyr") String yyr,
                                                        Model model) {
        if (ToolUtil.isOneEmpty(id,xj,xjbz,sumTodayCash,dianming,yaoma,yyr)) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        try {
            model.addAttribute("id", URLDecoder.decode(id, "UTF-8"));
            model.addAttribute("xj", URLDecoder.decode(xj, "UTF-8"));
            model.addAttribute("xjbz", URLDecoder.decode(xjbz, "UTF-8"));
            model.addAttribute("sumTodayCash", URLDecoder.decode(sumTodayCash, "UTF-8"));
            model.addAttribute("dianming", URLDecoder.decode(dianming, "UTF-8"));
            model.addAttribute("yaoma", URLDecoder.decode(yaoma, "UTF-8"));
            model.addAttribute("yyr", URLDecoder.decode(yyr, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        return PREFIX + "/btyPaymentOrderDetailsManualOperation.html";
        //return PREFIX + "/btyPaymentOrderDetails.html";
    }


    /**
     * 跳转到主页面
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyPaymentOrderDetails.html";
    }

    /**
     * 跳转到主页面
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("btyPaymentOrderDetailsSimple")
    public String btyPaymentOrderDetailsSimple(@RequestParam("bpoPayCode") String bpoPayCode,@RequestParam("dianming") String dianming,@RequestParam("bpoPaidCashAll") String bpoPaidCashAll,Model model) {
        if (ToolUtil.isOneEmpty(bpoPayCode,dianming,bpoPaidCashAll)) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        try {
            model.addAttribute("bpoPayCode", URLDecoder.decode(bpoPayCode, "UTF-8"));
            model.addAttribute("dianming", URLDecoder.decode(dianming, "UTF-8"));
            model.addAttribute("bpoPaidCashAll", URLDecoder.decode(bpoPaidCashAll, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        return PREFIX + "/btyPaymentOrderDetailsSimple.html";
    }

    /**
     * 新增页面
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyPaymentOrderDetails_add.html";
    }

    /**
     * 编辑页面
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyPaymentOrderDetails_edit.html";
    }

    /**
     * 新增接口
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        this.btyPaymentOrderDetailsService.add(btyPaymentOrderDetailsParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        this.btyPaymentOrderDetailsService.update(btyPaymentOrderDetailsParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        this.btyPaymentOrderDetailsService.delete(btyPaymentOrderDetailsParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        BtyPaymentOrderDetails detail = this.btyPaymentOrderDetailsService.getById(btyPaymentOrderDetailsParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wjk
     * @Date 2021-12-07
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        return this.btyPaymentOrderDetailsService.findPageBySpec(btyPaymentOrderDetailsParam);
    }


    /**
     * 查询根据订单编号查询列表
     *
     * @author wjk
     * @Date 2021-12-09
     */
    @ResponseBody
    @RequestMapping("/listByPayCode")
    public LayuiPageInfo listByPayCode(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        return this.btyPaymentOrderDetailsService.listByPayCode(btyPaymentOrderDetailsParam);
    }





    /**
     * 获取分页查询支付的一些列表
     *
     * @author wjk
     * @Date 2021-12-08
     *
     *
     *
     * @updatDate 2022-01-07
     * @updat  新增店内充值金额，计算汇总
     */
    @ResponseBody
    @RequestMapping("/searchPayPageList")
    public LayuiPageInfo searchPayPageList(BtyPaymentOrderAndYybbParam btyPaymentOrderAndYybbParam) {
        return this.btyPaymentOrderDetailsService.searchPayPageList(btyPaymentOrderAndYybbParam);
    }


    /**
     * 根据yybb的id,和现金实缴，生成手动支付订单，生成手动支付的现金额度，手动支付现金额度；
     *
     * @author wjk
     * @Date 2021-12-09
     *
     *
     *
     * @updatDate 2022-01-07
     * @updat  新增店内充值金额，计算汇总
     */
    @RequestMapping("/btyPaymentOrderDetailsForPaidCash")
    @ResponseBody
    public ResponseData btyPaymentOrderDetailsForPaidCash(BtyPaymentOrderDetailsParam btyPaymentOrderDetailsParam) {
        Map<String,String> map = this.btyPaymentOrderDetailsService.btyPaymentOrderDetailsForPaidCash(btyPaymentOrderDetailsParam);
        if(map.get("flag").equals("true")){
            return ResponseData.success(map);
        }else{
            return ResponseData.error(200,"失败。",map.get("msg"));
        }
    }

    /**
     * 获取查询支付的列表，导出查询
     *
     * @author wjk
     * @Date 2021-12-14
     */
    @ResponseBody
    @RequestMapping("/searchPayList")
    public ResponseData searchPayList(BtyPaymentOrderAndYybbParam btyPaymentOrderAndYybbParam) {
        List<BtyPaymentOrderAndYybbResult> list = this.btyPaymentOrderDetailsService.searchPayList(btyPaymentOrderAndYybbParam);
        return ResponseData.success(list);
    }

    /*
    *到店长信息跳转页面
    *ws
     */
    @RequestMapping("/searchCashBalance")
    public String searchCashBalance(@RequestParam("startDateTime") String startDateTime,
                                    @RequestParam("endDateTime") String endDateTime,
                                    @RequestParam("cashBalance") String cashBalance,
                                    @RequestParam("xjHave") String xjHave,
                                    @RequestParam("xjbzHave") String xjbzHave,
                                    @RequestParam("dm") String dm,
                                    @RequestParam("startbpoPayDatetime") String startbpoPayDatetime,
                                    @RequestParam("endbpoPayDatetime") String endbpoPayDatetime,
                                    Model model) {
        if (ToolUtil.isOneEmpty(startDateTime,endDateTime,cashBalance)) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        if (ToolUtil.isAllEmpty(xjHave,xjbzHave)) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        try {
            model.addAttribute("startDateTime", URLDecoder.decode(startDateTime, "UTF-8"));
            model.addAttribute("endDateTime", URLDecoder.decode(endDateTime, "UTF-8"));
            model.addAttribute("cashBalance", URLDecoder.decode(cashBalance, "UTF-8"));
            model.addAttribute("xjHave", URLDecoder.decode(xjHave, "UTF-8"));
            model.addAttribute("xjbzHave", URLDecoder.decode(xjbzHave, "UTF-8"));
            model.addAttribute("dm", URLDecoder.decode(dm, "UTF-8"));
            model.addAttribute("startbpoPayDatetime", URLDecoder.decode(startbpoPayDatetime, "UTF-8"));
            model.addAttribute("endbpoPayDatetime", URLDecoder.decode(endbpoPayDatetime, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RequestEmptyException("请求数据不完整！");
        }
        return PREFIX + "/btyPaymentOrderDetailsSengMsg.html";
    }
    /*
     *@author ws
     * @Date 2022-03-02
     * 查询所有的店长信息
     *  查询出有天才现金，充值现金，现金差额的符合条件的店，bty_area表查询所有考勤店长（以及无考勤店长的列表）
     */
    @ResponseBody
    @GetMapping("/searchCashBalance2")
    public Map<String,Object> searchCashBalance(BtyPaymentOrderAndYybbParam btyPaymentOrderAndYybbParam) {
        //查询条件判断
        Map<String,Object> map=new HashMap<>();
        if(ToolUtil.isEmpty(btyPaymentOrderAndYybbParam.getStartDateTime())||ToolUtil.isEmpty(btyPaymentOrderAndYybbParam.getEndDateTime())){
            map.put("code",0);
            map.put("msg","营业日期不能为空");
            map.put("count",0);
            map.put("data","");
            return map;
        }
        if(!btyPaymentOrderAndYybbParam.getXjHave().equals("2")&&!btyPaymentOrderAndYybbParam.getXjbzHave().equals("2")){
            map.put("code",0);
            map.put("msg","天才现金或充值现金至少一个有金额");
            map.put("count",0);
            map.put("data","");
            return map;
        }
        if(!btyPaymentOrderAndYybbParam.getCashBalance().equals("2")){
            map.put("code",0);
            map.put("msg","现金差额不能为空");
            map.put("count",0);
            map.put("data","");
            return map;
        }
        Map<String, Object> map1= this.btyPaymentOrderDetailsService.searchMenDianList(btyPaymentOrderAndYybbParam);
        return map1;
    }
    /*
     *@author ws
     * @Date 2022-03-02
     *  根据查询的店长信息，给微信公众号和小妖app以及畅聊推送消息
     */
    /**
     *
     *
     * 推送微信消息，对所有考勤店长
     * @author ws
     * @Date 2022-03-03
     */
    @ResponseBody
    @RequestMapping("/xjjzPushMsgToIMAndWx")
    public ResponseData xjjzPushMsgToIMAndWx(BtyPaymentOrderAndYybbParam btyPaymentOrderAndYybbParam) {

        Map<String,String> map = this.btyPaymentOrderDetailsService.xjjzPushMsgToIMAndWx(btyPaymentOrderAndYybbParam);
        if (String.valueOf(map.get("flag")).equals("true")) {
            return ResponseData.success(map);
        } else {
            return ResponseData.error(200, "失败", map);
        }

    }



    /**
     *
     *
     * 查询随行付账号分组
     * @author wjk
     * @Date 2022-07-04
     */
    @ResponseBody
    @RequestMapping("/getSuixingfuShopNumList")
    public ResponseData getSuixingfuShopNumList() {
        List<BtyPaymentOrderConfigMugua> list = this.btyPaymentOrderDetailsService.getSuixingfuShopNumList();
        return ResponseData.success(list);
    }


}


